<template>
    <div>
        <page-main>
            <el-row>
                <el-col :xs="24" :sm="12" :md="9" :lg="7" :xl="6">
                    <!--action必写，代表上传地址
                    on-preview	点击文件列表中已上传的文件时的事件
                    on-remove	文件列表移除文件时的事件
                    -->
                    <el-upload
                        ref="upload"
                        class="upload-demo"
                        action
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :file-list="fileList"
                        :auto-upload="false"
                        :http-request="uploadImg"
                    >
                        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
                        <el-button type="submit" @click="downloadAll">下载</el-button>
                        <el-button type="submit" @click="downloadAll(id,name)">...</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                    </el-upload>
                </el-col>
            </el-row>
        </page-main>
    </div>
</template>

<script>
import PageMain from '../../components/PageMain/index'
export default {
    name: 'task.summary',
    components: {PageMain},
    data() {
        return {
            // 上传列表数据
            fileList: [],
            asuccess: false,
            id: 11,
            name: ''
        }
    },
    methods: {
        // submitUpload() {
        //     this.$refs.upload.submit()
        // },
        // handleRemove(file, fileList) {
        //     console.log(file, fileList)
        // },
        // handlePreview(file) {
        //     console.log(file)
        // },
        // uploadImg(fileObj) {
        //
        //     let formData = new FormData()
        //     formData.set('file', fileObj.file)
        //     var _this = this
        //     api.post('/vue/upload', formData, {
        //
        //         headers: {
        //             'Content-type': 'multipart/form-data'
        //         }
        //     }).then(function(response) {
        //         // 根据响应的数据来进行判断文件上传后是否响应成功
        //         if (response.state == 1) {
        //             // 发送成功后
        //             _this.$message({
        //                 type: 'success',
        //                 message: '???'
        //             }),
        //             // 跳转路径
        //             _this.$router.push({path: '/school/publish_message'})
        //         }
        //     }).catch(
        //
        //     )
        // },
        // downloadAll() {
        //     window.location.href = 'http://192.168.31.130:8082/vue/download?file=已经打包后的文件'
        // }
    }

}
</script>
